package demo524;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class Update {
    public static void main(String[] args) throws ClassNotFoundException, SQLException{
        Connection connection = SqlConnection.getCon();
        Scanner  scanner = new Scanner(System.in);
        System.out.println("请输入用户id");
        int id = scanner.nextInt();
        System.out.println("请输入用户名");
        String  username = scanner.next();
        String sql = "update users set username=? where id=?";
        PreparedStatement  preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1,username);
        preparedStatement.setInt(2,id);
        int i = preparedStatement.executeUpdate();
        if (i>0){
            System.out.println("修改成功");
        }
        else {
            System.out.println("修改失败");
        }
    }
}
